#ifndef __BSP_TOUCH_CST816_H__
#define __BSP_TOUCH_CST816_H__



#include <stdint.h>
#include "stm32f4xx.h"

#define RCC_CST816_PORT (RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOB)		/* GPIO端口时钟 */

#define CST816_SDA_PORT	GPIOB
#define CST816_SDA_PIN	GPIO_Pin_4

#define CST816_SCL_PORT	GPIOB
#define CST816_SCL_PIN	GPIO_Pin_6

#define CST816_RST_PORT	GPIOA
#define CST816_RST_PIN	GPIO_Pin_15

#define CST816_INT_PORT	GPIOB
#define CST816_INT_PIN	GPIO_Pin_1

/* 设备地址 */
#define CST816_I2C_ADDR 0x2A

/* 触摸屏寄存器 */
#define GestureID 			    0x01
#define FingerNum 			    0x02
#define XposH 					0x03
#define XposL 					0x04
#define YposH 					0x05
#define YposL 					0x06
#define ChipID 					0xA7
#define SleepMode				0xE5
#define MotionMask 			    0xEC
#define IrqPluseWidth 	        0xED
#define NorScanPer 			    0xEE
#define MotionSlAngle 	        0xEF
#define LpAutoWakeTime 	        0xF4
#define LpScanTH 				0xF5
#define LpScanWin 			    0xF6
#define LpScanFreq 			    0xF7
#define LpScanIdac 			    0xF8
#define AutoSleepTime 	        0xF9
#define IrqCtl 					0xFA
#define AutoReset 			    0xFB
#define LongPressTime 	        0xFC
#define IOCtl 					0xFD
#define DisAutoSleep 		    0xFE


/* 触摸屏坐标结构体 */
typedef struct
{
	unsigned int X_Pos;
	unsigned int Y_Pos;
} CST816_Info;

/* 手势ID识别选项 */
typedef enum
{
	NOGESTURE = 	0x00,
	DOWNGLIDE = 	0x01,
	UPGLIDE = 		0x02,
	LEFTGLIDE = 	0x03,
	RIGHTGLIDE = 	0x04,
	CLICK = 		0x05,
	DOUBLECLICK =   0x0B,
	LONGPRESS = 	0x0C,
} GestureID_TypeDef;

/* 连续动作配置选项 */
typedef enum
{
	M_DISABLE = 	0x00,
	EnConLR = 		0x01,
	EnConUD = 		0x02,
	EnDClick = 		0x03,
	M_ALLENABLE =   0x07,
} MotionMask_TypeDef;

/* 中断低脉冲发射方式选项 */
typedef enum
{
	OnceWLP = 		0x00,
	EnMotion = 		0x10,
	EnChange = 		0x20,
	EnTouch = 		0x40,
	EnTest = 		0x80,
} IrqCtl_TypeDef;


/* 触摸屏初始化相关函数 */
void bsp_cst816_init(void); 
void bsp_cst816_reset(void); 

/* 触摸屏操作函数 */
void bsp_cst816_get_xy_axis(uint32_t *x_pos, uint32_t *y_pos);  
uint8_t bsp_cst816_get_chipid(void);
uint8_t bsp_cst816_get_fingernum(void);

/* 触摸屏有关参数配置函数 */
void bsp_cst816_set_AutoSleepTime(uint8_t time);
void bsp_cst816_set_MotionMask(uint8_t mode);
void bsp_cst816_set_MotionSlAngle(uint8_t x_right_y_up_angle);
void bsp_cst816_set_NorScanPer(uint8_t period);
void bsp_cst816_set_IrqPluseWidth(uint8_t width);
void bsp_cst816_set_LpScanTH(uint8_t th);
void bsp_cst816_sleep(void);
void bsp_cst816_wakeup(void);

#endif /* __BSP_TOUCH_CST816_H__ */
